<template>
  <el-dialog :visible.sync="visible" title="自定义和弦" width="320px" @close="onCancel">
    <el-form @submit.native.prevent>
      <el-form-item label="和弦名" :label-width="'60px'">
        <el-input v-model="chordName" placeholder="请输入和弦名" maxlength="12" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="onCancel">取消</el-button>
      <el-button type="primary" @click="onConfirm" :disabled="!chordName.trim()">确定</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: 'CustomChordDialog',
  props: {
    visible: Boolean
  },
  data() {
    return {
      chordName: ''
    }
  },
  watch: {
    visible(val) {
      if (val) this.chordName = ''
    }
  },
  methods: {
    onConfirm() {
      this.$emit('confirm', this.chordName.trim())
      this.chordName = ''
    },
    onCancel() {
      this.$emit('cancel')
      this.chordName = ''
    }
  }
}
</script> 